// 你访问 我的ip
// 我console.log  你的ip


var http =require('http');
var fs= require('fs');

var hostname = '192.168.13.5';
var port='3000';

var server = http.createServer(function(req,res){
    fs.readFile('./1.html',function(err,data){
        if (err) {res.end('baocuo');return;};

        var ip=getIp(req);
        console.log(req.url+"服务器ip是"+ip);
        res.end(data);
    });
});

server.listen(port,hostname);




//获取url请求客户端ip  封装的方法  仅供使用
var getIp = function(req) {
    var ip = req.headers['x-forwarded-for'] ||
        req.ip ||
        req.connection.remoteAddress ||
        req.socket.remoteAddress ||
        req.connection.socket.remoteAddress || '';
    if(ip.split(',').length>0){
        ip = ip.split(',')[0]
    }
    return ip;
}